using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;
using System.IO;

namespace Xtreme_Server
{
    public partial class HelpViewer : ComponentFactory.Krypton.Toolkit.KryptonForm
    {
        public HelpViewer()
        {
            InitializeComponent();

            this.ts.Renderer = new KryptonRenderer.KryptonStandardRenderer(new ComponentFactory.Krypton.Toolkit.KryptonColorTable2010(KryptonRenderer.Colors123._schemeColors, ComponentFactory.Krypton.Toolkit.InheritBool.True, ComponentFactory.Krypton.Toolkit.KryptonManager.PaletteOffice2010Blue));
        }

        private void HelpViewer_Load(object sender, EventArgs e)
        {
            string[] nodesln = File.ReadAllLines(Path.Combine(Application.StartupPath, "conf", "help", "nodes.dat"));
            foreach (string s in nodesln)
            {
                string u = s;
                TreeNode t = new TreeNode();
                if (!u.StartsWith("--"))
                {
                    u = u.Substring(1);
                    string nm = u.Substring(1, u.LastIndexOf(']') - 1);
                    t.Name = nm;
                    
                    string txt = u.Replace(nm, "").Replace("[", "").Replace("]", "").Replace("(", "").Replace(")", "");
                    t.Text = txt;
                    tv.Nodes.Add(t);
                }
                else
                {
                    u = u.Substring(2);
                    string parent = u.Substring(1, u.LastIndexOf(']') - 1);
                    //t.Parent = tv.Nodes[tv.Nodes.IndexOfKey(parent)];

                    //string nm = u.Replace(parent, "").Replace("[", "").Replace("]", "");
                    string nm = u.Substring(parent.Length) + 2;


                    nm = nm.Replace(nm.Substring(nm.IndexOf('(')), "");
                    nm = nm.Replace("{", "");
                    nm = nm.Replace("}", "");
                    nm = nm.Substring(nm.IndexOf(']') + 1);
                    t.Name = nm;


                    string txt = u.Replace(parent, "").Replace("[", "").Replace("]", "");
                    txt = txt.Substring(txt.IndexOf('('));
                    txt = txt.Replace("(", "").Replace(")", "");
                    t.Text = txt;
                    tv.Nodes[parent].Nodes.Add(t);
                    //tv.Nodes[tv.Nodes.IndexOfKey(parent)].Nodes.Add(t);
                }

            }
        }
    }
}